package com.safe.first.infrastructure.interceptor;

import com.safe.first.domain.user.DefaultUser;
import com.safe.first.domain.user.User;
import com.safe.first.domain.user.repo.UserRepo;
import lombok.AllArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * @author Mickey
 * @since 2022/6/10
 **/
@Component
@AllArgsConstructor
public class MyUserDetailService implements UserDetailsService {

    private final UserRepo userRepo;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userRepo.byUsername(username);
        return (DefaultUser) user;
    }

}
